﻿using System;
using System . Collections . Generic;
using System . Linq;
using System . Text;
using System . Threading . Tasks;
using System . Globalization;
using OrangeEndless . Properties;

namespace OrangeEndless
{
	public class Building
	{

		private decimal startcps;

		public decimal StartCps
		{
			get { return startcps; }
			set { startcps = decimal . Ceiling ( value ); }
		}

		private decimal starprice;

		public decimal StartPrice
		{
			get { return starprice; }
			set { starprice = decimal . Ceiling ( value ); }
		}

		private decimal number;

		public decimal Number
		{
			get { return number; }
			set { number = decimal . Ceiling ( value ); }
		}

		private decimal level;

		public decimal Level
		{
			get { return level; }
			set { level = decimal . Ceiling ( value ); }
		}

		public decimal Price
		{
			get
			{
				return decimal . Ceiling ( StartPrice * Convert . ToDecimal ( Math . Pow ( 1.15 , ( double ) Number ) ) );
			}
		}

		public decimal Cps
		{
			get
			{
				return decimal . Ceiling ( StartCps * Number * Convert . ToDecimal ( Math . Pow ( 2 , ( double ) Level ) ) );
			}
		}

		public string Name { get; set; }

		public string Introduction { get; set; }

		public string Id { get; set; }

		public void Suspend ( )
		{
			Settings . Default [ Id + "Level" ] = Level;
			Settings . Default [ Id + "Number" ] = Number;
		}

		public static Building LoadBuilding ( int key )
		{
			string id ="B" + key . ToString ( CultureInfo . InvariantCulture );
			var Temp = new Building
			{
				Name = BuildingsNameResource . ResourceManager . GetString ( id , CultureInfo . InvariantCulture ) ,
				Introduction = BuildingsIntroductionResource . ResourceManager . GetString ( id , CultureInfo . InvariantCulture ) ,
				StartCps = Convert . ToDecimal ( BuildingsStartCpsResource . ResourceManager . GetString ( id , CultureInfo . InvariantCulture ) , CultureInfo . InvariantCulture ) ,
				StartPrice = Convert . ToDecimal ( BuildingsStartPriceResource . ResourceManager . GetString ( id , CultureInfo . InvariantCulture ) , CultureInfo . InvariantCulture ) ,
				Level = ( decimal ) ( Settings . Default [ id + "Level" ] ?? ( object ) 0d ) ,
				Number = ( decimal ) ( Settings . Default [ id + "Number" ] ?? ( object ) 0d ) ,
				Id = id
			};
			return Temp;
		}
	}
}
